// 文章相关请求
import request from 'utils/request'

/**
 * 获取文章列表数据
 * @param {*} params
 * @returns
 */
export const getArticles = (params) => {
  return request({
    url: '/mp/articles',
    method: 'get',
    params,
  })
}

/**
 * 删除文章
 * @param {*} id 文章id
 * @returns
 */
export const delArticle = (id) => {
  return request({
    url: '/mp/articles/' + id,
    method: 'DELETE',
  })
}

/**
 * 添加文章
 * @param {Object} data 文章参数
 * @param {Boolean} draft 是否为草稿
 * @returns
 */
export const addArticle = (data, draft = false) => {
  return request({
    url: `/mp/articles?draft=${draft}`,
    method: 'POST',
    data,
  })
}

/**
 * 获取文章信息
 * @param {*} id 文章id
 * @returns
 */
export const getArticleInfo = (id) => {
  return request({
    url: `/mp/articles/${id}`,
    method: 'GET',
  })
}

/**
 * 修改文章
 * @param {*} data
 * @param {Boolean} draft 是否为草稿
 * @returns
 */
export const editArticle = (data, draft) => {
  return request({
    url: `/mp/articles/${data.id}?draft=${draft}`,
    method: 'PUT',
    data,
  })
}
